package org.study.javafx.study01.tab.code;

import javafx.application.Application;
import javafx.geometry.*;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import lombok.extern.slf4j.Slf4j;
import org.study.javafx.study01.AppStarter;
import org.study.javafx.study01.config.AppConfig;

/**
 * 参考 https://blog.csdn.net/ceclar123/article/details/140898349
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2024年08月18日
 */
@Slf4j
public class TabCode2 extends Application {
    /**
     * 直接运行此方法会报如下错误：
     * 错误: 缺少 JavaFX 运行时组件, 需要使用该组件来运行此应用程序
     * 请运行 {@link AppStarter#main(String[])}
     */
    public static void main(String[] args) {
        AppConfig.init();
        launch(args);
    }

    @Override
    public void init() throws Exception {
        super.init();
    }

    @Override
    public void start(Stage stage) throws Exception {
        TabPane tabPane = new TabPane();
        // 内边距
        tabPane.setPadding(new Insets(10, 10, 10, 10));
        // 位置
        tabPane.setSide(Side.TOP);
        // 关闭策略
        tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.SELECTED_TAB);
        // 拖拽策略
        tabPane.setTabDragPolicy(TabPane.TabDragPolicy.REORDER);
        tabPane.setRotateGraphic(false);
        tabPane.setCenterShape(false);

        Tab tab1 = new Tab("Tab-1");
        FlowPane flowPane1 = new FlowPane();
        flowPane1.setOrientation(Orientation.HORIZONTAL);
        for (int i = 1; i <= 5; i++) {
            flowPane1.getChildren().add(new Button("Button-" + i));
        }
        tab1.setContent(flowPane1);

        Tab tab2 = new Tab("Tab-2");
        FlowPane flowPane2 = new FlowPane();
        flowPane2.setOrientation(Orientation.VERTICAL);
        for (int i = 6; i <= 10; i++) {
            flowPane2.getChildren().add(new Button("Button-" + i));
        }
        tab2.setContent(flowPane2);
        tabPane.getTabs().addAll(tab1, tab2);

        Scene scene = new Scene(new VBox(tabPane), 500, 300);
        stage.setTitle("JavaFx布局示例：TabPane");
        stage.setScene(scene);
        stage.show();
    }

    @Override
    public void stop() throws Exception {
        super.stop();
    }
}
